<header class="header navbar bg-white shadow">
  <div class="btn-group tool-button">
    <button class="btn btn-danger navbar-btn" onclick="delCheck()"><i class="ti-close"></i> 清空日志</button>
  </div>
</header>
<div class=panel-body style="padding-top: 50px;">
  <div class="table-responsive no-border">
    <input id="unitid" type="hidden">
    <table class="table table-bordered table-striped mg-t datatable">
      <thead>
      <tr>
        <th>日志类型</th>
        <th>访问路径</th>
        <th>日志内容</th>
        <th>操作人</th>
        <th>操作时间</th>
        <th>操作IP</th>
    </table>
  </div>
</div>
<div id="dialogDelete" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">删除</h4>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-xs-12">
            删除后无法恢复，确定删除吗？ <br/>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
        <button id="ok" type="button" class="btn btn-primary" data-loading-text="正在删除...">确 定</button>
      </div>
    </div>
  </div>
</div>
<script language="JavaScript">
  var datatable;
  function initDatatable() {
    datatable = $('.datatable').DataTable({
      "dom": '<"toolbar">frtip',
      "searching": false,
      "processing": false,
      "serverSide": true,
      "select": true,
      "ordering": true,
      "language": {
        "url": "/plugins/datatables/cn.json"
      },
      "preDrawCallback": function () {
        sublime.showLoadingbar($(".main-content"));
      },
      "drawCallback": function () {
        sublime.closeLoadingbar($(".main-content"));
      },
      "ajax": {
        "url": "/private/sys/log/data",
        "type": "post",
        "data": function (d) {
        }
      },
      "order": [[4, "desc"]],
      "columns": [
        {"data": "type", "bSortable": true},
        {"data": "url", "bSortable": true},
        {"data": "note", "bSortable": true},
        {"data": "createdByName", "bSortable": true},
        {"data": "createdAt", "bSortable": true},
        {"data": "createdIp", "bSortable": true}
      ],
      "columnDefs": [
        {
          "render": function (data, type, row) {
            if (data) {
              return new Date(parseInt(data*1000)).Format("yyyy-MM-dd hh:mm:ss");
            }
          },
          "targets": 4
        }
      ]
    });
    datatable.on('click', 'tr', function () {
      $(this).toggleClass('selected');
    });
    $("#searchBtn").on('click', function () {
      datatable.ajax.reload();
    });
  }
  function delCheck() {
    var dialog = $("#dialogDelete");
    dialog.modal("show");
    dialog.find("#ok").unbind("click");
    dialog.find("#ok").bind("click", function (event) {
      var btn = $(this);
      btn.button("loading");
      $.post("/private/sys/log/delete", {}, function (data) {
        if (data.code == 0) {
          datatable.ajax.reload(null,false);
        } else {
          Toast.error(data.msg);
        }
        btn.button("reset");
        dialog.modal("hide");
      }, "json");
    });
  }
  $(function () {
    initDatatable();
  });
</script>
